{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from service.BaseEngine import BaseEngine\n",
      "from utils.auto_load import AutoLoad\n",
      "import pandas as pd\n",
      "from influxdb.resultset import ResultSet\n",
      "from numpy import datetime64"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "loader = AutoLoad()\n",
      "engine = loader.auto_load_engine_default(method='SHESD')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "service = BaseEngine(engine=engine,db_name='example',measurement='vc1', number_of_days=30)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Engine is already\n",
        "Connect to database server\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "result = service.query_analyzed()\n",
      "sorted_res = result.tz_convert(None).sort(ascending=True)\n",
      "result = result."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Get latest time series points\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "c = service.engine.fit_predict(sorted_res['value'])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 25
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "c = service.engine.produce()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 26
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "c.head()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>value</th>\n",
        "      <th>anomaly</th>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>timestamp</th>\n",
        "      <th></th>\n",
        "      <th></th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>2016-04-04 08:46:00</th>\n",
        "      <td>0.042143</td>\n",
        "      <td>1.0</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2016-04-04 08:47:00</th>\n",
        "      <td>0.041672</td>\n",
        "      <td>1.0</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2016-04-04 08:48:00</th>\n",
        "      <td>0.041384</td>\n",
        "      <td>1.0</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2016-04-04 08:49:00</th>\n",
        "      <td>0.045894</td>\n",
        "      <td>1.0</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2016-04-04 08:50:00</th>\n",
        "      <td>0.048850</td>\n",
        "      <td>1.0</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 27,
       "text": [
        "                        value  anomaly\n",
        "timestamp                             \n",
        "2016-04-04 08:46:00  0.042143      1.0\n",
        "2016-04-04 08:47:00  0.041672      1.0\n",
        "2016-04-04 08:48:00  0.041384      1.0\n",
        "2016-04-04 08:49:00  0.045894      1.0\n",
        "2016-04-04 08:50:00  0.048850      1.0"
       ]
      }
     ],
     "prompt_number": 27
    }
   ],
   "metadata": {}
  }
 ]
}